package com.qf.common;

import com.qf.aop.annocation.LoginUser;
import com.qf.resp.ResultEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@Component
public class ExceptionHanlder {

    // 业务异常(程序员手动抛出的异常)
    @ExceptionHandler(ShopException.class)
    @ResponseBody
    public ResultEntity businessException(ShopException e) {
        System.out.println("出现了业务异常");
        System.out.println(e);
        return ResultEntity.error(e.getMsg());
    }

    // 系统异常(程序员写的bug)
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ResultEntity systemException(Exception e) {
        System.out.println("系统出现异常了");
        System.out.println(e);
        return ResultEntity.error("系统正在维护。请稍后再试。。。");
    }
}
